using System;
using System.Collections.Generic;

namespace RollManager.Library.ActionSteps
{
    [Serializable]
    public class HistoryStep : ActionStep
    {
        private int m_subActionId;

        public override string Name
        {
            get { return string.Empty; }
        }

        /// <summary>
        /// Needed for serialization
        /// </summary>
        public HistoryStep() {}

        public HistoryStep( int subActionId )
        {
            m_subActionId = subActionId;
        }

        protected override void Run()
        {
            // Get history items for action.
            List<History> historyItems = Database.GetHistory( m_subActionId );
            if( historyItems.Count < 1 )
            {
                Progress.Add( "No history for given action." );
                return;
            }

            // Display each history item.
            Progress.Add( "Date\t\t\tResult\t\tUser\t\tContext" );
            foreach( History item in historyItems )
            {
                Progress.AddFormat( "{0}\t{1}\t{2}\t{3}", item.Date, item.Result, item.UserName, item.Context );
            }
        }

        protected override void Simulate()
        {
            // No simulation here.
        }
    }
}
